//
//  CustomTabBarController.m
//  ProjectFrame
//
//  Created by RubyJobs on 2018/11/9.
//  Copyright © 2018 个人. All rights reserved.
//

#import "CustomTabBarController.h"
#import "CustomNavigationController.h"
@interface CustomTabBarController ()

@end

@implementation CustomTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    //设置多有UITabBarItem的文字属性
    [self setupTitleTextAttributes];
    //添加子控制器
    [self setupChildViewControllers];
    //如果是5个按钮的话 其中中间还为自定义的比较大的那种
}
#pragma mark - 设置多有UITabBarItem的文字属性
- (void)setupTitleTextAttributes{
    //获取所有按钮
    UITabBarItem *items = [UITabBarItem appearance];
    //点击状态下文字颜色 字号
    NSMutableDictionary *selectedattrs = [NSMutableDictionary dictionary];
    selectedattrs[NSForegroundColorAttributeName] = [UIColor redColor];
    //属性放在所有按钮
    [items setTitleTextAttributes:selectedattrs forState:UIControlStateSelected];
}
#pragma mark - 添加子控制器
- (void)setupChildViewControllers{
    [self setupOneChildViewController:[[CustomNavigationController alloc] initWithRootViewController:[[UIViewController alloc] init]] title:@"首页" image:@"tabBar_essence_icon" selectedImage:@"tabBar_essence_click_icon"];
    [self setupOneChildViewController:[[CustomNavigationController alloc] initWithRootViewController:[[UIViewController alloc] init]] title:@"第二页" image:@"tabBar_new_icon" selectedImage:@"tabBar_new_click_icon"];
    
    [self setupOneChildViewController:[[CustomNavigationController alloc] initWithRootViewController:[[UIViewController alloc] init]] title:@"第三页" image:@"tabBar_friendTrends_icon" selectedImage:@"tabBar_friendTrends_click_icon"];
    
    [self setupOneChildViewController:[[CustomNavigationController alloc] initWithRootViewController:[[UIViewController alloc] init]]title:@"第四页" image:@"tabBar_me_icon" selectedImage:@"tabBar_me_click_icon"];
}

/**
 *  初始化一个子控制器
 *
 *  @param vc         子控制器类名
 *  @param title         标题
 *  @param image         图标
 *  @param selectedImage 选中图标
 */
- (void)setupOneChildViewController:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage{
    
    vc.tabBarItem.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:image];
    //加载图片
    UIImage *tempImage = [UIImage imageNamed:selectedImage];
    //产生一张不会被渲染的图片
    UIImage *seleImage= [tempImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    vc.tabBarItem.selectedImage = seleImage;
    
    [self addChildViewController:vc];
}

@end
